package com.moli.iov.task.jobhandler;

import com.moli.iov.alarm.model.po.StatAlarm;
import com.moli.iov.alarm.remote.IAlarmQuantityStatRemoteService;
import com.moli.iov.his.remote.IHisStatRemoteService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.sys.model.po.Company;
import com.moli.iov.sys.remote.ICompanyRemoteService;
import com.moli.iov.util.ConstactUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.List;

/**
 * <p>
 *  同步 上线统计Job
 * </p>
 *
 * @author lws
 * @version 3.0
 * @since 2019/10/21 10:39 AM.
 */
@Slf4j
@JobHander(value = "onlineStatHandler")
@Component
public class OnlineStatHandler extends IJobHandler {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    IHisStatRemoteService hisStatRemoteService;

    @Override
    public ReturnT<String> execute(String... param) throws Exception {
        //发送时间类型，0，0点发送；1，9点发送
        log.info("执行上线统计任务....");
        long start = System.currentTimeMillis();
        try {
            taskExecutor.execute(() -> {
                hisStatRemoteService.statOnline();
            });
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("定时报警统计失败", e);
        }
        log.info("执行完成上线统计任务，耗时：{}",(System.currentTimeMillis()-start));
        return ReturnT.SUCCESS;
    }
}
